package org.xhnews.ui;

import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.component.SeparatorField;
import net.rim.device.api.ui.container.HorizontalFieldManager;
import net.rim.device.api.ui.container.PopupScreen;
import net.rim.device.api.ui.container.VerticalFieldManager;

import org.xhnews.bo.RssBo;
import org.xhnews.notifications.EventManager;
import org.xhnews.to.RssChannel;

public class DelRssChnnlPopupScreen extends PopupScreen{
	private RssChannel _rsschannel;
	private ScreenClosedListener listener;
	public DelRssChnnlPopupScreen(RssChannel rsschannel,ScreenClosedListener listener) {
		super(new VerticalFieldManager(), Field.FOCUSABLE);
		this.listener=listener;
		_rsschannel=rsschannel;
		LabelField field=new LabelField("确认要删除"+rsschannel.getName()+"?");
        add(field);
		add(new SeparatorField());
		FieldChangeListener sbcl = new FieldChangeListener() {
			public void fieldChanged(Field field, int context) {
				RssBo.delRssChannelById(_rsschannel.getId());
				EventManager.fireEvent();
				close();
			}
		};
		FieldChangeListener cbcl = new FieldChangeListener() {
			public void fieldChanged(Field field, int context) {
				close();
			}
		};
		HorizontalFieldManager buttons = new HorizontalFieldManager(Field.FIELD_HCENTER | Field.USE_ALL_WIDTH);
		ButtonField submitButton = new ButtonField("确认");
		submitButton.setChangeListener(sbcl);
		buttons.add(submitButton);
		
		ButtonField cancelButton = new ButtonField("取消");
		cancelButton.setChangeListener(cbcl);
		buttons.add(cancelButton);
		add(buttons);

	}	
	protected void onUndisplay() {
	       listener.notifyScreenClosed(this);
	    } 
}
